package com.graduate.after.utils;

import com.graduate.after.constants.StatusCode;
import com.graduate.after.exception.GraduateException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GraduateExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception exception){
        GraduateException graduateException = null;
        if(exception instanceof GraduateException){
            graduateException= (GraduateException) exception;
        }else{
            graduateException= new GraduateException(StatusCode.SYSTEM_INNER_ERROR);
            // 方便开发阶段看报错情况，项目写完删除即可
            exception.printStackTrace();
        }
        return Result.fail(graduateException.getStatusCode());
    }

}
